import _ from './lodash'


function throttle(callback, option = {}) {
    let optiton = {
        duration: 150,
        trailing: true,
        ...option
    };
    return _.throttle(callback, optiton.duration, {
        trailing: optiton.trailing,
    });
}

function debounce(callback, option = {}) {
    let optiton = {
        duration: 500,
        leading: false,
        ...option
    };
    return _.debounce(callback, optiton.duration, {
        leading: true,
        trailing: false
    })
}

function getRequestId() {
    return Math.floor(Math.pow(16, 7) * (Math.random() * 15 + 1)).toString(16);
}

function to(promise) {
    return promise.then((data) => ([null, data]))
        .catch((err) => [err]);
}

export {
    throttle,
    debounce,
    getRequestId,
    to
};
